package com.tiejun.ge.redis.controller;

import com.tiejun.ge.common.core.domain.R;
import com.tiejun.ge.common.redis.configure.RedisClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;

/**
 * @program: springboot
 * @description: redisController
 * @author: getiejun
 * @create: 2025-08-26 23:59
 **/
@RestController
@Slf4j
public class RedisController {

    @Resource
    private RedisClient redisClient;

    @GetMapping("/test1")
    public R<?> helloWorld() {
        Boolean result = redisClient.hasKey("test_key");
        if(!result) {
            log.info(">>缓存中值不存在，重新设置");
            redisClient.setCacheObject("test_key", "test_value", 30L, TimeUnit.SECONDS);
        } else {
            log.info(">>缓存中值存在，从缓存中获取");
        }
        return R.success(redisClient.getCacheObject("test_key"));
    }
}
